﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test1_22Jan
{
    class Program
    {
        static void Main(string[] args)
        {
            //1Task
            //Number10();

            //2Task
            //FindSum();

            //2Task рекурсия
            //int number;
            //Console.WriteLine("Enter number");
            //bool success = Int32.TryParse(Console.ReadLine(), out number);
            //if (success)
            //    Console.WriteLine("Sum of all previous numbers is {0}", FindSumRecursion(number));
            //else
            //    Console.WriteLine("You typed not corresponding number");

            //3Task
            //FindDistance();

            //4Task
            //FindQuater();

            //5Task
            Console.WriteLine("Enter symbol");
            char symbol = Char.Parse(Console.ReadLine());
            Console.WriteLine("Enter height");
            int h = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Enter width");
            int w = Int32.Parse(Console.ReadLine());
            DrawPicture(symbol, h, w);

            //6Task
            //Console.WriteLine("Enter size");
            //int s = Int32.Parse(Console.ReadLine());
            //foreach (var item in RandomArray(s))
            //{
            //    Console.Write(item + " ");
            //}

            //7task
            //FindEvenOdd();

            //8th task
            //FindMinMaxValue();
        }
        static void Number10()
        {
            int number;
            Console.WriteLine("Enter number");
            bool success = Int32.TryParse(Console.ReadLine(),out number);
            if (success)
                Console.WriteLine(number+10);
            else
                Console.WriteLine("You typed not corresponding number");
        }
        static void FindSum()
        {
            int Sum = 0;
            int number;
            Console.WriteLine("Enter number");
            bool success = Int32.TryParse(Console.ReadLine(), out number);
            if (success && number>0)
            {
                for (int i = 0; i <= number; i++)
                {
                    Sum += i;
                }
                Console.WriteLine(Sum);
            }
            else
                Console.WriteLine("You typed not corresponding number");
        }
        static int FindSumRecursion(int num)
        {
            int Sum = 0;
            if (num == 1)
                return 1;
            else
                Sum = FindSumRecursion(num - 1) + num;
            return Sum;
        }
        static void FindDistance()
        {
            double ValueX = 0;
            double ValueY = 0;
            Console.WriteLine("Enter x");
            double x1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter y");
            double y1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter x");
            double x2 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter y");
            double y2 = Double.Parse(Console.ReadLine());

            if (x1 > x2)
                ValueX = x1 - x2;
            if (x2 > x1)
                ValueX = x2 - x1;
            if (y1 > y2)
                ValueY = y1 - y2;
            if (y2 > y1)
                ValueY = y2 - y1;

            double result = Math.Sqrt(ValueY * ValueY + ValueX * ValueX);
            Console.WriteLine("Length is {0:#.##}", result);
        }
        static void FindQuater()
        {
            Console.WriteLine("Enter x");
            double x1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Enter y");
            double y1 = Double.Parse(Console.ReadLine());
            if (x1<0)
            {
                if (y1<0)
                    Console.WriteLine("3rd quater");
                else
                    Console.WriteLine("2nd quater");
            }
            if (x1 > 0)
            {
                if (y1 < 0)
                    Console.WriteLine("4th quater");
                else
                    Console.WriteLine("1st quater");
            }
            if (x1==0)
                Console.WriteLine("Point is on abscissa");
            if (y1 == 0)
                Console.WriteLine("Point is on ordinate");
            if (x1 == 0 && y1==0)
                Console.WriteLine("Origin");
        }
        static void DrawPicture (char s, int height, int width)
        {
            for(int i = 1; i < height + 1; i++)
            {
                if (i == 1)
                {
                    for (int j = 1; j < width+1; j++)
                    {
                        Console.Write(s);
                    }
                    Console.Write("\n");
                }
                else if (i>1 && i< height)
                {
                    for (int j = 1; j < width + 1; j++)
                    {
                        if (j==1)
                            Console.Write(s);
                        else if (j > 1 && j < width)
                            Console.Write(" ");
                        else
                            Console.Write(s);
                    }
                    Console.Write("\n");
                }
                else if (i == height)
                {
                    for (int j = 1; j < width+1; j++)
                    {
                        Console.Write(s);
                    }
                    Console.Write("\n");
                }
            }
        }
        static int[] RandomArray(int size)
        {
            int[] array = new int[size];
            Random rnd = new Random();
            for (int i=0; i<size; i++)
            {
                array[i] = rnd.Next(1, 1000);
            }
            return array;
        }
        static void FindEvenOdd()
        {
            int countEven = 0;
            int countOdd = 0;
            int[] array = new int[5];
            Random rnd = new Random();
            for (int i = 0; i < 5; i++)
            {
                array[i] = rnd.Next(1, 1000);
                Console.WriteLine(array[i]);
                if (array[i] % 2 == 0)
                {
                    countEven++;
                }
                if (array[i] % 2 != 0)
                {
                    countOdd++;
                }
            }
            Console.WriteLine("Even - {0} Odd - {1}", countEven, countOdd);
        }
        static void FindMinMaxValue()
        {
            int counterMin = 0;
            int counterMax = 0;
            int[] array = new int[20];
            Random rnd = new Random();
            for (int i = 0; i < 20; i++)
            {
                array[i] = rnd.Next(1, 20);
                Console.Write(array[i] + " ");
            }
            Console.WriteLine(  );
            foreach (var item in array)
            {
                if (item == array.Min())
                {
                    counterMin++;
                }
                if (item == array.Max())
                {
                    counterMax++;
                }
            }
            Console.WriteLine(@"Min value - {0} first index {1} repeats {2} times
Max value - {3} first index {4} repeats {5} times", array.Min(), Array.IndexOf(array, array.Min())+1, counterMin, 
array.Max(), Array.IndexOf(array, array.Max())+1, counterMax);
        }
    }
}
